-- Effects --
-- Index
-- [QUA] Quake

-- Quake Effect [QUA]
QuakeEffect = {}
QuakeEffect.__index = QuakeEffect

function QuakeEffect.new()
    local q = {}
    setmetatable(q, QuakeEffect)
    
    -- variables
    q.x = 0.0
    q.y = 0.0
    q.active = false
    q.intensity = 1.0
    q.interval = 0.1
    q.length = 1.0
    q.interval_time = 0.0
    
    return q
end

-- play
function QuakeEffect:play(length, interval, intensity)
    if not self.active then
        self.length = length
        self.interval = interval
        self.intensity = intensity
        self.active = true
    end
end

-- stop
function QuakeEffect:stop()
    self.active = false
    self.x = 0.0
    self.y = 0.0
end

-- update
function QuakeEffect:update()
    if self.active then
        if self.length >= 0.0 then
            self.length = self.length - global_delta_time
            
            self.interval_time = self.interval_time + global_delta_time
            if self.interval_time > self.interval then
                self.interval_time = 0.0
                
                local x_quake = math.random() * self.intensity
                local y_quake = math.random() * self.intensity
                
                self.x = -self.intensity + (x_quake * 2)
                self.y = -self.intensity + (y_quake * 2)
            end
        else
            self:stop()
        end
    end
end